//
//  SPReviewCell.m
//  Sport
//
//  Created by Cass on 2018/1/30.
//  Copyright © 2018年 Cass. All rights reserved.
//

#import "SPReviewCell.h"
#import "YYLabel.h"
#import "YYText.h"
#import "SPComment.h"
#import "SPCommentFrame.h"
@interface SPReviewCell ()

/** 文本内容 */
@property (nonatomic , weak) YYLabel *contentLabel;

@end

@implementation SPReviewCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

+ (instancetype)cellWithTableView:(UITableView *)tableView{
    static NSString *ID = @"cell";
    SPReviewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
//        cell = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([SPReviewCell class]) owner:nil options:nil].lastObject;
        cell = [[self alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self _setup];
        [self _setupSubViews];
    }
    return self;
}

- (void)setCommentFrame:(SPCommentFrame *)commentFrame{
    _commentFrame = commentFrame;
    SPComment *comment = commentFrame.comment;
    
    self.contentLabel.frame = commentFrame.textFrame;
    self.contentLabel.attributedText = comment.attributedText;
}
- (void)_setup{
    //设置颜色
    self.backgroundColor = [UIColor whiteColor];
    self.contentView.backgroundColor = [UIColor whiteColor];
}
//- (void)setModel:(SPCommentModel *)model{
//    _model = model;
//    NSString *commentName = model.commentName;
//    NSString *textString = model.textString;
//    YYLabel *contentLabel = [[YYLabel alloc]initWithFrame:CGRectMake(20, 5, 200, 20)];
//    contentLabel.numberOfLines = 0;
//    contentLabel.textAlignment = NSTextAlignmentLeft;
//    NSString *commentString = [NSString stringWithFormat:@"%@:%@",commentName,textString];
//    NSMutableAttributedString *text = [[NSMutableAttributedString alloc]initWithString:commentString];
//    [text addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:19] range:NSMakeRange(0, text.length)];
//    //设置行距
//    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];
//    style.lineSpacing = 3;
//    [text addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, text.length)];
//    [text yy_setTextHighlightRange:NSMakeRange(0, commentName.length) color:[UIColor grayColor] backgroundColor:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
//        NSLog(@"click");
//    }];
//    contentLabel.attributedText = text;
//    [contentLabel sizeToFit];
//    [self.contentView addSubview:contentLabel];
//    self.contentLabel = contentLabel;
//}
- (void)_setupSubViews{
//    SPCommentModel *model = self.model;
//    NSString *userName = model.userName;
//    NSString *commentName = model.commentName;
//    NSString *textString = model.textString;
//    YYLabel *contentLabel = [[YYLabel alloc]initWithFrame:CGRectMake(0, 0, 100, 20)];
//    contentLabel.numberOfLines = 0;
//    contentLabel.textAlignment = NSTextAlignmentLeft;
//    NSString *commentString = [NSString stringWithFormat:@"%@:%@",commentName,textString];
//    NSMutableAttributedString *text = [[NSMutableAttributedString alloc]initWithString:commentString];
//    [text addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:19] range:NSMakeRange(0, text.length)];
//    //设置行距
//    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];
//    style.lineSpacing = 3;
//    [text addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, text.length)];
//    [text yy_setTextHighlightRange:NSMakeRange(0, commentName.length) color:[UIColor grayColor] backgroundColor:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
//        NSLog(@"click");
//    }];
//    contentLabel.attributedText = text;
//    [contentLabel sizeToFit];
//    [self.contentView addSubview:contentLabel];
//    self.contentLabel = contentLabel;
    //文本
    YYLabel *contentLabel = [[YYLabel alloc]init];
    contentLabel.numberOfLines = 0;
    contentLabel.textAlignment = NSTextAlignmentLeft;
    [self addSubview:contentLabel];
    self.contentLabel = contentLabel;
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

- (void)layoutSubviews{
    [super layoutSubviews];
}
@end
